<%-- 
  -- Body List para Body.
  --
  -- @author ariel.piechotka
--%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<%@ taglib uri="/WEB-INF/displaytag-el.tld" prefix="display" %>
<%@ taglib uri="/WEB-INF/security.tld" prefix="security" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<%-- Librerias para EXT library --%>
<link rel="stylesheet" type="text/css" href="<html:rewrite page='/protected/script/ext-1.1.1/resources/css/ext-all.css'/>" />
<link rel="stylesheet" type="text/css" href="<html:rewrite page='/protected/script/ext-1.1.1/resources/css/xtheme-default.css'/>" />

<script src="<html:rewrite page='/protected/script/ext-1.1.1/adapter/ext/ext-base.js'/>" type="text/javascript"></script>
<script src="<html:rewrite page='/protected/script/ext-1.1.1/ext-all.js'/>" type="text/javascript"></script>

<script type="text/javascript">
    function modifyBody(bodyCode) {
        var hiddenBodyCode = $("modifyIdId");
        hiddenBodyCode.value = bodyCode;        
        var form = $("modifyBodyFormId");
        form.submit();
    } 

    function preDeleteBody(bodyCode, name) {
        // Deja el documento y el pais del cliente a borrar en dos hidden
        var localHiddenBodyObj = $("bodyToDeleteId");
        localHiddenBodyObj.value = bodyCode;

        Ext.MessageBox.confirm('Confirm', '&iquest;Est&aacute; seguro que desea eliminar el ente ' + name + '?', postDeleteBody);
    }
    
   /** Post invocacion de la eliminacion de body. */
    var postDeleteBody = function(btn)  {
        var localHiddenBodyObj = $("bodyToDeleteId");
        if (btn == "yes") {
            // Se quiere eliminar efectivamente
            var deleteHiddenObj = $("deleteBodyCode");
            deleteHiddenObj.value = localHiddenBodyObj.value;
            
            var form = $("deleteBodyFormId");
            form.submit();
        }
        else {
            localHiddenNameObj.value = "";
        }
    }
</script>


<%-- El ID del form NO debe ser modificado. Se usa desde el menu --%>
<html:form action="/protected/listBodies.do" styleId="bodyFormId">
    <%-- Inyectados por Javascript --%>
    <html:hidden name="bodyForm" property="bodyCode" styleId="bodyToDeleteId" value=""/>
    <%-- No pertenece al form de Struts. Se carga cada vez q se selecciona un ente a eliminar --%>
<%-- !    <input type="hidden" id="bodyToDeleteId" value="" > --%>
    
    <h2>Entes</h2>

    <bean:define id="bodies" name="bodyForm" property="bodies" />
    <display:table name="pageScope.bodies" sort="list" export="true" pagesize="15" requestURI="/protected/listBodies.do" id="row" class="displayTable">

        <display:column title="Eliminar" class="columnGifLink" media="html">
            <img src="<html:rewrite page='/protected/img/trashcan_full.png'/>" alt="" name="submitButton" onclick="preDeleteBody('<bean:write name="row" property="code" />', '<bean:write name="row" property="name" />')" title="Elimina al ente...">
        </display:column>

        <display:column title="Modificar" class="columnGifLink" media="html">
            <img src="<html:rewrite page='/protected/img/kedit.png'/>" alt="" name="submitB" onclick="modifyBody('<bean:write name="row" property="code" />')" title="Modifica al ente...">
        </display:column>

        <display:column title="Codigo" property="code" sortable="true" />
        <display:column title="Nombre" property="name" sortable="true" />
    </display:table>    

</html:form>

<%-- Inyectados por Javascript --%>
<div id="modifyDivId" class="hideClass">
    <html:form action="/protected/showBody" styleId="modifyBodyFormId">
        <html:hidden property="code" value="" styleId="modifyIdId" />
    </html:form>
</div>

<%-- Inyectados por Javascript --%>
<div id="deleteDivId" class="hideClass">
    <html:form action="/protected/deleteBody" styleId="deleteBodyFormId">
        <html:hidden property="bodyCode" value="" styleId="deleteBodyCode" />
    </html:form>
</div>
